<?php
//Iskysoft文章类
//用于写产品的相关替换函数
include(dirname(__FILE__).'/../public/public_article.php');
class IskysoftArticle  extends PublicArticle {
	
	function __construct($arr = NULL){

	}
	
	//得到首页头部广告
	function getIndexTopAd($get = array() ) {

		$str = '';
		$rows = $this->getIndexTopAdInfo($get);
		if (!empty($rows)) {
			
			$row_size = explode('*', $rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			$str = '<div class="topbanner"><a href="'.$ad_url.'">
					<img src="'.$rows['ad_photo'].'"   alt="'.$rows['ad_alt'].'" width="'.$row_size[0].
					'" height="'.$row_size[1].'" /></a></div>';
		}
		return $str;
	}
	
	//得到首页分类信息
	function getIndexCategory($get = array() ) {
	
		//推荐6个专题
		$cat_id_str =  '';
		$data = $this->getIndexCategoryInfo($get);
		extract($data['web_date']);

		$res = $GLOBALS['db']->query($data['sql']);
		unset($data);
		
		$str = '<div class="resourceMain">';
		while ($row = $GLOBALS['db']->fetch_array($res)) {
			
			$cat_url = url_new_replace($row['url'], $urlType);
			if ($cat_id_str!='') {
				$cat_id_str .= ','.$row['cat_id'];
			} else {
				$cat_id_str = $row['cat_id'];
			}
			
			$str .= '<div class="item">
					<div class="title"><a href="'.$cat_url.'">'.$row['cat_title'].'</a></div>
					<div class="img"><a href="'.$cat_url.'"><img alt="'.$row["cat_title"].'" title="'.$row["cat_title"].'" 
					src="'.$row["cat_thumb"].'" border="0"/></a></div>';
			
			$sql = "SELECT ar.ar_id ,ar.ar_title,ar.ar_introduction ,tab.url 
					FROM topic_article ar 
					LEFT JOIN $temArtTable tab ON ar.ar_id = tab.$temArtId 
					WHERE ar.ar_cat_id = ".$row['cat_id']." AND ar.is_delete =0 AND ar.is_recommend = 1 AND ar.web_type = $WebFage 
					ORDER BY update_time DESC LIMIT 3 ";
			
			$resa = $GLOBALS['db']->query($sql);
			
			$j = 0;
			while ($rowa = $GLOBALS['db']->fetch_array($resa)) {
				
				if (!getURL(DOC_ROOT.$rowa['url'])) {
					continue;
				}
				
				$atr_url = url_new_replace($rowa['url'], $urlType); 
				
				if ($j == 0) {
					$str.='<dl class="news"><dt><a href="'.$atr_url.'">'.$rowa['ar_title'].'</a></dt>
					<dd>'.$rowa['ar_introduction'].'</dd> ';
				} else {
					$str.='<dt><a href="'.$atr_url.'">'.$rowa['ar_title'].'</a></dt>';
				}
				$j = $j +1;
			}
			
			if ($j > 0)
			$str.='</dl>';
			$str.='<div class="btn"><a href="'.$cat_url.'" >More</a></div></div>';
		}
		
		$str.='<div class="clear"></div></div>';
		//一般专题
		$str.='<div class="resource_bottom"><div class="item1 r_bottom"><div class="title">Browse Topics</div>
				<div class="box_main">';
		
		$sql = 'SELECT cate.cat_title,cate.cat_id,tab.url 
				FROM category AS cate 
				LEFT JOIN '.$temCatTable.' AS tab ON cate.cat_id= tab.'.$temCatId.' 
				WHERE !FIND_IN_SET(cate.cat_id,"'.$cat_id_str.'") AND cate.is_delete = 0 AND cate.cat_type = 1 AND cate.cat_web = '.$WebFage.' AND cate.cat_series = 3 
				ORDER BY cate.add_time DESC ';
		$res = $GLOBALS['db']->query($sql);
		
		$str .='<ul class="topics_list">';
		while ($row = $GLOBALS['db']->fetch_array($res)) {
			
			$cat_url = url_new_replace($row['url'], $urlType);
			$str .='<li><a href="'.$cat_url.'">'.$row['cat_title'].'</a></li>';
		}
		$str .='</ul><div class="clear"></div></div></div>';
		//热门标签
		$str .='<div class="item2"><div class="title">Hot Tags</div><div class="box_tags">';	
		
		$sql = 'SELECT c.tag_name,t.url 
				FROM tag c 
				LEFT JOIN '.$temTagTable.' t ON t.'.$temTagId.' = c.tag_id 
				WHERE c.is_hot=1 AND c.is_delete =0 AND c.tag_web = '.$WebFage;
		$result = $GLOBALS['db']->query($sql);
		
		$i=0;
		while ($rs = $GLOBALS['db']->fetch_array($result)) {
			
			$url = url_new_replace($rs['url'], $urlType);
			if (($i + 1) % 3 == 0) {
				$str .='<a class="two" href="'.$url.'">'.$rs['tag_name'].'</a> ';
			} else if (($i + 1) % 2 == 0) {
				$str.='<a class="one" href="'.$url.'">'.$rs['tag_name'].'</a> ';
			} else {
				$str.='<a href="'.$url.'">'.$rs['tag_name'].'</a> ';
			}
			$i++;
		}
		
		$str.='</div></div>';
		//热门文章
		$str.='<div class="item3"><div class="title">Hot Articles</div><ul class="hot_list">';		
		$sql = "SELECT c.ar_subtitle,t.url 
				FROM topic_article c 
				LEFT JOIN $temArtTable t ON t.$temArtId = c.ar_id 
				WHERE c.is_hot = 1 AND c.is_delete = 0 AND c.web_type = $WebFage 
				ORDER BY c.update_time DESC LIMIT 4 ";
		$result = $GLOBALS['db']->query($sql);
		
		while ($rs = $GLOBALS['db']->fetch_array($result)) {
			
			if (!getURL(DOC_ROOT.$rs['url'])) {
				continue;
			}
			$url = url_new_replace($rs['url'],$urlType);
			$str.=' <li><a href="'.$url.'">'.$rs['ar_subtitle'].'</a></li>';
		}
		$str.='</ul></div><div class="clear"></div><div class="return"><a href="#header">Back to top</a></div></div>';

		return $str;
	}
	
	//得到文章主分类
	function getArticleMainCategory($get = array() ) {
		
		
		$data = $this->getArticleMainCategoryInfo($get);
		extract($data['web_date']);
		
		if (!empty($data['rows'][trim($temCatName)])) {
			
			$url = url_new_replace($data['rows']['url'], $urlType);
		 	return '<a href="'. $url.'">'.$data['rows'][trim($temCatName)].'</a> ';
		 	
		} else {
			return '';
		}
		
	}
	
	
	//得到热门文章列表
	function getArticleHotList($get = array() ) {
		
		if (empty($get['文章ID'])) {
			return '';
		} else {
			$ar_id = $get['文章ID'];
		}
		
		extract($this->getWebTablesData($get['web_type']));//把数组分解成变量
		
		$nums = 0;
		$str_hot = '';
		$operation_type = 'hots';
		$sql = "SELECT `ar_cat_id` 
				FROM topic_article 
				WHERE `ar_id`=".$ar_id;
		$ar_cat_id = $GLOBALS['db']->getOne($sql);
		
		if (empty($ar_cat_id)) {
			return '';
		}
		
		$sql = 'SELECT c.ar_subtitle,t.url,c.ar_id 
				FROM '.$temArtTable.' t 
				LEFT JOIN topic_article c ON t.'.$temArtId.' = c.ar_id 
				WHERE c.ar_cat_id = '.$ar_cat_id.' AND c.is_hot = 1 AND c.is_delete=0 AND c.web_type = '.$WebFage.' 
				ORDER BY c.update_time DESC LIMIT 0,10 ';
		$result = $GLOBALS['db']->query($sql);
		
		$hot_article_id = '';
		while ($row = $GLOBALS['db']->fetch_array($result)) {
			
			$hot_article_id .=  empty($hot_article_id) ? $row['ar_id'] : ','.$row['ar_id'];
			$url = url_new_replace($row['url'], $urlType);
			$str_hot.=' <li><a href="'.$url.'">'.$row['ar_subtitle'].'</a></li>';
			$nums ++;
		}
		//如果推荐文章木有六条则随机取10-推荐的文章数量
		if ($nums < 10) {
			//以下是判断随机表里是否存在
			$sql = 'SELECT 	recommend_article 
					FROM article_right_recommend 
					WHERE    topic_cat_id = '.$ar_cat_id.' AND article_hots_id = "'.$hot_article_id.'" 
							AND web_type = '.$WebFage.' AND operation_type = "'.$operation_type.'" ';
			$rows = $GLOBALS['db']->getAll($sql);
			
			$type = '';
			//如果不存在则随机取产品相关分类的文章产品10-推荐的文章数量 条数
			if (empty($rows[0])) {
			
				$sql = 'SELECT ar.ar_id,ar.ar_subtitle,tab.url 
						FROM topic_article ar 
						LEFT JOIN '.$temArtTable.' tab ON tab.'.$temArtId.' = ar.ar_id 
						WHERE ar.web_type = '.$WebFage.' AND ar.is_delete = 0 AND ar_cat_id = '.$ar_cat_id.' AND !FIND_IN_SET(ar_id,"'.$hot_article_id.'") 
						ORDER BY RAND() LIMIT '.(10-$nums );

				$type = 'insert';//表示为新增到随机表中 保持每次发布时  随机文章不变
			
			} else {
				$sql = 'SELECT ar.ar_id,ar.ar_subtitle,tab.url 
						FROM topic_article ar 
						LEFT JOIN '.$temArtTable.' tab ON tab.'.$temArtId.' = ar.ar_id 
						WHERE FIND_IN_SET(ar_id,"'.$rows[0]['recommend_article'].'") ';
				
			}
			$result = $GLOBALS['db']->query($sql);
			
			$rand_article_id = '';
			while ($row = $GLOBALS['db']->fetch_array($result)) {
				$url = $row['url'];
				$rand_article_id .= empty($rand_article_id) ? $row['ar_id'] : ','.$row['ar_id'];
				$url = url_new_replace($row['url'],$urlType);
				$str_hot .= '<li><a href="'.$url.'" >'.$row['ar_subtitle'].'</a></li>';
			}
			
			if ($type == 'insert') {
				$sql = 'DELETE 
						FROM article_right_recommend 
						WHERE topic_cat_id = '.$ar_cat_id.' AND web_type = '.$WebFage.' AND operation_type = "'.$operation_type.'" ';
				$GLOBALS['db']->query($sql);
				
				$sql = 'INSERT INTO article_right_recommend(web_type,topic_cat_id,recommend_article ,operation_type,add_user,add_time,
						update_user,update_time,article_hots_id) 
						VALUES ('.$WebFage.',"'.$ar_cat_id.'","'. $rand_article_id.'","'.$operation_type.'","'.$_SESSION['AName'].'",
								"'.$_SERVER['REQUEST_TIME']. '","'.$_SESSION['AName'].'","'.$_SERVER['REQUEST_TIME'].'","'.$hot_article_id.'")';
				$GLOBALS['db']->query($sql);
			}
		}
		
		if ($str_hot == "") {
			return '';
		}
		unset($row);
		return $str_hot;
	}
	
	
	//得到热门标签
	function getArticleHotTag($get = array() ) {
	
		$str = '';	
		
		$data = $this->getArticleHotTagInfo($get);
		extract($data['web_date']);
		$result = $GLOBALS['db']->query($data['sql']);

		$i = 0;
		while ($rows = $GLOBALS['db']->fetch_array($result)) {
			
			$url = url_new_replace($rows['url'],$urlType);

			if (($i + 1) % 3 == 0) {
				$str.='<a class="two" href="'.$url.'">'.$rows['tag_name'].'</a>';
			} else {
				$str.='<a href="'.$url.'">'.$rows['tag_name'].'</a> ';
			}
			$i++;
		}
		
		unset($rows, $data);
		return $str;
	}
	
	//得到相关文章
	function getArticleRelated($get = array() ) {
		
		$data = $this->getArticleRelatedInfo($get);
		extract($data['web_date']);
		
		$str = '<h4 class="av_bottom_title">Related Articles</h4><ul class="av_bottom_list">';
		if ($data['related_article']) {
			
			$sql = "SELECT c.ar_title,t.url 
					FROM topic_article c 
					LEFT JOIN {$temArtTable} t ON t.{$temArtId} = c.ar_id 
					WHERE c.web_type = {$WebFage} AND FIND_IN_SET(c.ar_id,'{$data['related_article']}') AND c.is_delete= 0 
					ORDER BY t.CreateTime DESC LIMIT 3 ";
			$result = $GLOBALS['db']->query($sql);
			
			while ($rows = $GLOBALS['db']->fetch_array($result)) {
				$url = url_new_replace($rows['url'], $urlType);
				$str .= ' <li><a href="'.$url.'">'.$rows['ar_title'].'</a></li>';
			}
		}else {
			return '';
		}
		
		$str .= '</ul>';
		unset($rows);
		return $str;
	}
	
		//得到文章右侧广告
	function getArticleLeftAd($get = array() ) {
		
		$str = '';
		$rows = $this->getArticleLeftAdInfo($get);
		if (!empty($rows)) {
			
			$row_size = explode('*', $rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			$str = '<div class="r_side_banner"><a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"  
			alt="'.$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
		}
		unset($rows, $row_size);
		return $str;
	}
	
	//得到文章头部广告
	function getArticleTopAd($get = array() ) {
		
		$str = '';
		$rows = $this->getArticleTopAdInfo($get);
		if (!empty($rows)) {
			
			$row_size = explode('*', $rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			
			$str = '<div class="topbanner"><a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   
			alt="'.$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
		}
		
		unset($rows);
		return $str;
	

	}
	
	//得到文章评论
	function getArticleComments($get = array() ) {
	
		$data = $this->getArticleCommentsInfo($get);
		
		$str = '';
		foreach ( $data as $v ) {
			$str .= '<li><div class="disqus_name">'.$v['author'].'&nbsp&nbsp'.$v['time'].
			'</div><div class="disqus_message">'.$v['message'].'</div></li>';
		}
		return $str ? '<ul>'.$str.'</ul>' : '';
	}
	
	//note 作者信息
	function getAuthorInfo( $get ){
		
		$aid = $get['文章ID'];
		
		$sql = "SELECT art.update_time, aut.author, aut.email, aut.avatar, aut.gaccount, t72.url, t72.Field_20692 AS cat_name FROM topic_article AS art
				LEFT JOIN author AS aut ON art.author_id = aut.aid
				LEFT JOIN Table_72 AS t72 ON t72.Field_20690 = art.ar_cat_id
				WHERE art.ar_id = '{$aid}'";	
		$row = $GLOBALS['db']->getOneRs($sql);
		
		if( empty($row['author']) ) return '';

		$url = str_replace( array('/iskysoft.com/httpdocs/','index.html'), array('http://www.iskysoft.com/',''), $row['url'] );

		$str = '<div class="articleInfo">
				<a class="fl" href="'.$row['gaccount'].'"><img src="'.$row['avatar'].'" width="60" height="60" /></a>
				<p><abbr class="published" title="'.date('Y-m-d', $row['update_time']).'">'.date('Y-m-d H:i:s', $row['update_time']).'</abbr> / 
				Posted by <a href="'.$row['gaccount'].'" rel="author">'.$row['author'].'</a> to <a href="'.$url.'">'.$row['cat_name'].'</a><br>
            	<a href="'.$row['email'].'">Follow @'.end(explode('/',$row['email'])).'</a></p>
				</div>';
		return $str;
	}
	
	
	//得到专题推荐文章
	function getSubjectRecommendArticle($get = array()) {
		
		$str = '';
		$data = $this->getSubjectRecommendArticleInfo($get);
		extract($data['web_date']);
		$result = $GLOBALS['db']->query($data['sql']);
		
		while($rs = $GLOBALS['db']->fetch_array($result)) {
			
			$url = url_new_replace($rs['url'], $urlType);
			$str .= '<div class="item"><a href="'.$url.'"><img src="'.$rs['ar_image'].'" border="0" width="160" height="120" 
					alt="'.$rs['ar_subtitle'].'" title="'.$rs['ar_subtitle'].'" /></a> <div class="title"><a href="'.$url.'">
					'.$rs['ar_title'].'</a></div>
					<div class="time"><!--'.substr(date("r", $rs['MendTime']), 0, -5).'--></div>
					<div class="info">'.$rs['ar_introduction'].'</div></div>';
		}
		unset($rs);
		return $str;
	}
	
	//得到专题热门标签
	function getSubjectHotTags($get = array()) {
		
		$str = '';
		$data = $this->getSubjectHotTagsInfo($get);
		extract($data['web_date']);
		$result = $GLOBALS['db']->query($data['sql']);
		
		$i = 0;
		while ($rs = $GLOBALS['db']->fetch_array($result)) {
			
			$url = url_new_replace($rs['url'], $urlType);
			if (($i + 1) % 3 == 0) {
				$str.='<a class="two" href="'.$url.'">'.$rs['tag_name'].'</a>';
			} else {
				$str.='<a href="'.$url.'">'.$rs['tag_name'].'</a> ';
			}
			$i++;
		}
		unset($rs);
		return $str;
	}
	
	//得到专题热门文章列表
	function getSubjectHotArticleList($get = array()) {
		
		$str = '';
		$data = $this->getSubjectHotArticleListInfo($get);
		extract($data['web_date']);
		$result = $GLOBALS['db']->query($data['sql']);
		
		while ($rs = $GLOBALS['db']->fetch_array($result)) {    
			        
			if (!getURL(DOC_ROOT.$rs['url'])) {
				continue;
			}
			
			$url = url_new_replace($rs['url'], $urlType);
			$str.=' <li><a href="'.$url.'">'.$rs['ar_subtitle'].'</a></li>';
		}
		unset($rs);
		return $str;
	}
	
	
	//得到专题头部广告
	function getSubjectTopAd($get = array() ) {
		
		$str = '';
		$rows = $this->getSubjectTopAdInfo($get);
		if (!empty($rows)) {
			
			$row_size = explode('*',$rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			$str = '<div class="topbanner"><a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   
					alt="'.$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
		}
		
		unset($rows);
		return $str;
		

	}
	
	//得到专题头部广告
	function getSubjectLeftAd($get = array() ) {
		
		$str = '';
		$rows = $this->getSubjectLeftAdInfo($get);
		
		if (!empty($rows)) {
			$row_size = explode('*',$rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			$str = '<div class="r_side_banner"><a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"  
			 alt="'.$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
		}
		unset($rows);
		return $str;
		

	}
	
	//得到标签热门标签
	function getTagHots($get = array() ) {
		
		$str = '';
		$data = $this->getTagHotsInfo($get);
		extract($data['web_date']);
		$result = $GLOBALS['db']->query($data['sql']);
		
		$i = 0;
		while($rs = $GLOBALS['db']->fetch_array($result)) {
			
			$url = url_new_replace($rs['url'], $urlType);
			if (($i + 1) % 3 == 0) {
				$str.='<a class="two" href="'.$url.'">'.$rs['tag_name'].'</a>';
			} else {
			 $str.='<a href="'.$url.'">'.$rs['tag_name'].'</a> ';
			}
			$i++;
		}
		
		unset($rs);
		return $str;
	}
	
	
	//得到标签热门文章列表
	function getTagHotArticleList($get = array() ) {
		
		$str ='';	
		extract($this->getWebTablesData($get['web_type']));//把数组分解成变量	
		$tagid = $get['标签ID'];	
		$str = $str_hot = $not_hot_article_str = '';	
		
		$sql = "SELECT c.ar_subtitle , t.url ,c.ar_id 
				FROM $temArtTable t 
				LEFT JOIN topic_article c ON t.$temArtId = c.ar_id 
				WHERE FIND_IN_SET('".$tagid."',c.ar_tag_id) AND c.is_hot = 1 AND c.is_delete =0 AND c.web_type = $WebFage LIMIT 0 , 10";
		$result = $GLOBALS['db']->query($sql);
		
		$nums = 0;
		$hot_article_id = '';
		while ($rs = $GLOBALS['db']->fetch_array($result)) {
			 
			$hot_article_id .=  empty($hot_article_id) ? $rs['ar_id'] : ','.$rs['ar_id'];
			$url = url_new_replace($rs['url'], $urlType);
			$str_hot .= ' <li><a href="'.$url.'">'.$rs['ar_subtitle'].'</a></li>';
			$nums = $nums + 1;
		}
		//如果推荐文章木有十条则随机取10-推荐的文章数量
		if ($nums < 10) {
			
			if ($hot_article_id != '') {
				$not_hot_article_str = ' AND !FIND_IN_SET(ar_id,"'.$hot_article_id.'") ';
			}
			$sql = 'SELECT ar.ar_id,ar.ar_subtitle,tab.url 
					FROM '.$temArtTable.' tab 
					LEFT JOIN topic_article ar ON tab.'.$temArtId.' = ar.ar_id 
					WHERE ar.web_type = '.$WebFage.' AND ar.is_delete = 0 AND FIND_IN_SET('.$tagid.',ar.ar_tag_id) '.$not_hot_article_str.' 
					ORDER BY RAND() LIMIT '.(10-$nums );
			$result = $GLOBALS['db']->query($sql);
			
			while ($row = $GLOBALS['db']->fetch_array($result)) {
				
				$url = url_new_replace($row['url'], $urlType);
				$str_hot.= '<li><a href="'.$url.'" >'.$row['ar_subtitle'].'</a></li>';
				
			}
		}
		
		if (empty($str_hot)) {
			return '';
		}
		unset($row);
		return $str_hot;
	}
	
	//得到标签头部广告
	function getTagLeftAd($get = array() ) {

		$str = '';
		$rows = $this->getTagLeftAdInfo($get);
		if (!empty($rows)) {
			
			$row_size = explode('*', $rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			$str = '<div class="r_side_banner"><a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'" 
			alt="'.$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
		}
		
		unset($rows);
		return $str;
	}
	
	//得到标签头部广告
	function getTagTopAd($get = array() ) {
		$str = '';
		$rows = $this->getTagTopAdInfo($get);
		
		if (!empty($rows)) {
			
			$row_size = explode('*', $rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			$str = '<div class="topbanner"><a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   
			alt="'.$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
		}

		unset($rows);
		return $str;
	}
	
	

	//得到专题生成分页
	function getSubjectCreatePage($get = array() ) {
		
		$name = $get['专题名称'] ;
		$arr = $this->getSubjectCreatePageInfo($get);
		$total = $arr['total'];
		$max_page = $arr['max_page'];
		$dirurl = $arr['dirurl'];
		$dir = $arr['dir'];
		$template_str = $arr['template_str'];
		$all = $arr['all'];
		extract($this->getWebTablesData($get['web_type']));//把数组分解成变量	
		
		for ($i = 1; $i <= $max_page; $i++)  {
			
			$temp = $template_str;
			$list = '';
			$page_start=($i-1) * 10 + 1;
			$page_end=($i-1) * 10 + 10;
			
			if($page_end >= $total){
				$page_end = $total;
			}
			
			$chang_sum = 0;
			
			for ($j = ($i - 1)* 10; $j <= $i * 10 - 1; $j++)  {
				
				if ($j >= $total) {
					break;
				}
				
				$url = url_new_replace($all[$j]['url'], $urlType);
				$chang_sum = $chang_sum + 1;
				$list.='<dl>
				<dt><a href="'.$url.'">'.$all[$j]['ar_title'].'</a><span><!--'.substr(date("r",$all[$j]['update_time']),0,-5).'--></span></dt>
				<dd>'.$all[$j]['ar_introduction'].'</dd>
				</dl>';
			}
			//分页
			$page = '<div class="tag_list_page">';
			
			if ( $i  > 1 ) {
				if ($i -1 == 1)
				{
					$page .= '<a href="'.'../'.$dirurl.'/" class="prev">Prev</a>';
				} else {
					$page .= '<a href="'.'../'.$dirurl.'/'.($i-1).'.html" class="prev">Prev</a>';
				}
			} else  {
				$page .= '<a class="prev">Prev</a>';
			}
			
			$start = $i - 4;
			$end = $i + 4;
			
			if ($start < 1) {
				$start = 1; 
				$end = 6;
			}
			
			if ($end > $max_page) 
			{
				$end = $max_page; 
				$start = $max_page - 5;
			}
			
			if ($start < 1) {
				$start = 1;
			}
			
			if ($start != 1) {
				$output .= '';
			}
			
			for ($start; $start <= $end; $start++)  {
				
				if ($i == $start)  {
					$page .= '<strong>'.$start.'</strong>';
				} else  {
					
					if ($start == 1) {
						$page .= '<a href="'.'../'.$dirurl.'/">'.$start.'</a>';
					} else {
						$page .= '<a href="'.'../'.$dirurl.'/'.$start.'.html">'.$start.'</a>';
					}
				}
			}
			 
			if ($end != $max_page) {
				$output .= '';
			}
			
			if ($i < $max_page)  {
				$page .= '<a href="'.'../'.$dirurl.'/'.($i+1).'.html" class="next">Next</a>';
			} else  {
				$page .= '<a class="next">Next</a>';
			}
			
			$page.='</div>';
			$page = $list.$page;//列表与分页div合并
			if (isset($get['do']) && $get['do'] == 'view') {
				return $page;
			}
			$title = $get['页面title'];
			$temp = str_replace("<!--page_module-->", $page, $temp);
			$temp = str_replace('$'.'{专题生成分页}', '', $temp);
			$temp = str_replace('$'.'{页面关键字}', $get['页面关键字'], $temp);
			$temp = str_replace('$'.'{页面描述}', $get['页面描述'], $temp);
			$temp = str_replace('$'.'{页面title}', $title.' of '.$i, $temp);
			$temp = str_replace('$'.'{专题列表和分页信息}', $page, $temp);
			$temp = str_replace('$'.'{头文件}', $this->headerFile($get), $temp);
			$temp = str_replace('$'.'{脚文件}', $this->footerFile($get), $temp);
			$temp = str_replace('$'.'{专题名称}', $name, $temp);
			
			$temp = str_replace('$'.'{专题图片}', $this->getSubjectImage($get), $temp);
			$temp = str_replace('$'.'{专题简介}', $this->getSubjectIntroduction($get), $temp);
			$temp = str_replace('$'.'{专题推荐文章}', $this->getSubjectRecommendArticle($get), $temp);
			$temp = str_replace('$'.'{专题热门文章列表}', $this->getSubjectHotArticleList($get), $temp);
			$temp = str_replace('$'.'{专题右侧广告}', $this->getSubjectLeftAd($get), $temp);
			$temp = str_replace('$'.'{专题头部广告}', $this->getSubjectTopAd($get), $temp);
			$temp = str_replace('$'.'{专题热门标签}', $this->getSubjectHotTags($get), $temp);
			$str_link  = '';
			if ($max_page == 1) {
				$temp = str_replace('$'.'{专题link代码}',$str_link,$temp);
			} else if ($i == 1 ) {
				
				$str_link = '<link rel="next" href="'.'../'.$dirurl.'/'.($i+1).'.html"/>';
				$temp = str_replace('$'.'{专题link代码}', $str_link, $temp);
			} else if($i >1 && $i < $max_page) {
				
				$str_link = '<link rel="canonical" href="'.'../'.$dirurl.'/'.'"/>';
				
				if (($i-1) == 1) {
					$str_link .= '<link rel="prev" href="'.'../'.$dirurl.'/"/>';
				} else {
					$str_link .= '<link rel="prev" href="'.'../'.$dirurl.'/'.($i-1).'.html"/>';
				}
				
				$str_link .= '<link rel="next" href="'.'../'.$dirurl.'/'.($i+1).'.html"/>';
				$temp = str_replace('$'.'{专题link代码}', $str_link, $temp);
				
			} else if ($i == $max_page) {
				
				$str_link = '<link rel="canonical" href="'.'../'.$dirurl.'/'.'"/>';
				if (($i-1) == 1) {
					$str_link .= '<link rel="prev" href="'.'../'.$dirurl.'/"/>';
				} else {
					$str_link .= '<link rel="prev" href="'.'../'.$dirurl.'/'.($i-1).'.html"/>';
				}
				$temp = str_replace('$'.'{专题link代码}', $str_link, $temp);
			}
			
			if ($i == 1) {
				file_put_contents($dir.'/index.html', $temp);
			} else {
				file_put_contents($dir.'/'.$i.'.html', $temp);
			}

		}
	}
	
	//得到标签生成分页
	function getTagCreatePage($get = array() ) {
		
		$name = $get['标签名称'] ;
		$arr = $this->getTagCreatePageInfo($get);
		$total = $arr['total'];
		$max_page = $arr['max_page'];
		$dirurl = $arr['dirurl'];
		$dir = $arr['dir'];
		$template_str = $arr['template_str'];
		$all = $arr['all'];
		extract($this->getWebTablesData($get['web_type']));//把数组分解成变量	
		
		for ($i = 1; $i <= $max_page; $i++)  {
			
			$temp = $template_str;
			$page_start = ($i-1) * 10 + 1;
			$page_end = ($i-1) * 10 + 10;
			
			if ($page_end >= $total){
				$page_end = $total;
			}
			
			$list = '<h2 class="r_column"><strong>'.$name.'</strong> <span>'.$page_start.' - '.$page_end.' of '.$total.' 
			articles of tag '.$name.'</span></h2>
			<div class="tag_list">';
			
			$chang_sum = 0;
			for ($j = ($i - 1)* 10; $j <= $i * 10 - 1; $j++)  {
				
				if ($j >= $total) {
					break;
				}
		
				$url = url_new_replace($all[$j]['url'], $urlType);
				$chang_sum = $chang_sum + 1;
				$list.='<dl><dt><a href="'.$url.'">'.$all[$j]['ar_title'].'</a><span><!--'.substr(date("r", $all[$j]['update_time']), 0, -5).'--></span></dt>
				<dd>'.$all[$j]['ar_introduction'].'</dd>
				</dl>';
			}
			//分页
			$page = '<div class="tag_list_page">';
			if ( $i  > 1 ) {
				if ($i -1 == 1)
				{
					$page .= '<a href="'.'../../'.$dirurl.'/" class="prev">Prev</a>';
				} else {
					$page .= '<a href="'.'../../'.$dirurl.'/'.($i-1).'.html" class="prev">Prev</a>';
				}
			} else {
				$page .= '<a class="prev">Prev</a>';
			}
			
			$start = $i - 4;
			$end = $i + 4;
			
			if ($start < 1) {
				$start = 1;
				$end = 6;
			}
			
			if ($end > $max_page) {
				$end = $max_page; 
				$start = $max_page - 5;
			}
			
			if ($start < 1) {
				$start = 1;
			}
			
			if ($start != 1) {
				$output .= '';
			}
			
			for ($start; $start <= $end; $start++) {
				
				if ($i == $start)  {
					$page .= '<strong>'.$start.'</strong>';
				} else  {
					if ($start == 1) {
						$page .= '<a href="'.'../../'.$dirurl.'/">'.$start.'</a>';
					} else {
						$page .= '<a href="'.'../../'.$dirurl.'/'.$start.'.html">'.$start.'</a>';
					}
				}
			}
			
			if ($end != $max_page) {
				$output .= '';
			}
			
			if ($i < $max_page)  {
				$page .= '<a href="'.'../../'.$dirurl.'/'.($i+1).'.html" class="next">Next</a>';
			} else  {
				$page .= '<a class="next">Next</a>';
			}
			
			$page.='</div>';
			$page = $list.$page.'</div>';//列表与分页div合并
			if (isset($get['do']) && $get['do'] == 'view') {
				return $page;
			}
			$temp = str_replace("<!--page_module-->", $page, $temp);
			$temp = str_replace('$'.'{标签生成分页}', '', $temp);
			$temp = str_replace('$'.'{页面关键字}', $get['页面关键字'], $temp);
			$temp = str_replace('$'.'{页面描述}', $get['页面描述'], $temp);
			$temp = str_replace('$'.'{页面title}', $get['页面title'].' of '.$i, $temp);
			$temp = str_replace('$'.'{头文件}', $this->headerFile($get), $temp);
			$temp = str_replace('$'.'{脚文件}', $this->footerFile($get), $temp);
			$temp = str_replace('$'.'{标签名称}', $name, $temp);
			
			$temp = str_replace('$'.'{标签热门文章列表}', $this->getTagHotArticleList($get), $temp);
			$temp = str_replace('$'.'{标签热门标签}', $this->getTagHots($get), $temp);
			$temp = str_replace('$'.'{标签右侧广告}', $this->getTagLeftAd($get), $temp);
			$temp = str_replace('$'.'{标签头部广告}', $this->getTagTopAd($get), $temp);
			$str_link  = '';
			
			if ($max_page == 1) {
			
				$temp = str_replace('$'.'{标签link代码}', $str_link, $temp);
			} else if ($i == 1 ) {
				
				$str_link = '<link rel="next" href="'.'../../'.$dirurl.'/'.($i+1).'.html"/>';
				$temp = str_replace('$'.'{标签link代码}', $str_link, $temp);
			} else if($i >1 && $i < $max_page) {
				
				$str_link = '<link rel="canonical" href="'.'../../'.$dirurl.'/'.'"/>';
				if (($i-1) == 1) {
					$str_link .= '<link rel="prev" href="'.'../../'.$dirurl.'/"/>';
				} else {
					$str_link .= '<link rel="prev" href="'.'../../'.$dirurl.'/'.($i-1).'.html"/>';
				}
				
				$str_link .= '<link rel="next" href="'.'../../'.$dirurl.'/'.($i+1).'.html"/>';
				$temp = str_replace('$'.'{标签link代码}', $str_link, $temp);
				
			} else if($i == $max_page) {
				
				$str_link = '<link rel="canonical" href="'.'../../'.$dirurl.'/'.'"/>';
				if (($i-1) == 1) {
					$str_link .= '<link rel="prev" href="'.'../../'.$dirurl.'/"/>';
				} else {
					$str_link .= '<link rel="prev" href="'.'../../'.$dirurl.'/'.($i-1).'.html"/>';
				}
				
				$temp = str_replace('$'.'{标签link代码}', $str_link, $temp);
			}
			
			if ($i == 1) {
				file_put_contents($dir.'/index.html', $temp);
			} else {
				file_put_contents($dir.'/'.$i.'.html', $temp);
			}
		}
	}
}
?>